/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pp.entites;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author arnaud
 */
@Entity
@Table(name = "mobiledevice")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Mobiledevice.findAll", query = "SELECT m FROM Mobiledevice m"),
    @NamedQuery(name = "Mobiledevice.findById", query = "SELECT m FROM Mobiledevice m WHERE m.id = :id")})
public class Mobiledevice implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "id")
    private String id;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "mobiledevice")
    private List<MobiledeviceHasEvenement> mobiledeviceHasEvenementList;
    @JoinColumn(name = "idsite", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Site idsite;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idmobileDevice")
    private List<Allocationid> allocationidList;

    public Mobiledevice() {
    }

    public Mobiledevice(String id) {
        this.id = id;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @XmlTransient
    public List<MobiledeviceHasEvenement> getMobiledeviceHasEvenementList() {
        return mobiledeviceHasEvenementList;
    }

    public void setMobiledeviceHasEvenementList(List<MobiledeviceHasEvenement> mobiledeviceHasEvenementList) {
        this.mobiledeviceHasEvenementList = mobiledeviceHasEvenementList;
    }

    public void addMobiledeviceHasEvenement(MobiledeviceHasEvenement mobileEvt){
        if(!hasMobiledeviceHasEvenement(mobileEvt))
            this.mobiledeviceHasEvenementList.add(mobileEvt);
    }
    
    public MobiledeviceHasEvenement getMobiledeviceHasEvenement(MobiledeviceHasEvenementPK mobileEvtPK){
        MobiledeviceHasEvenement retour = null;
        for(MobiledeviceHasEvenement mobileEvt : this.mobiledeviceHasEvenementList){
            if(mobileEvt.getMobiledeviceHasEvenementPK().equals(mobileEvtPK)){
                retour = mobileEvt;
            }
        }
        return retour;
    }
    
    public boolean hasMobiledeviceHasEvenement(MobiledeviceHasEvenement mobileEvt){
        return (getMobiledeviceHasEvenement(mobileEvt.getMobiledeviceHasEvenementPK()) != null);
    }
    
    public Site getIdsite() {
        return idsite;
    }

    public void setIdsite(Site idsite) {
        this.idsite = idsite;
    }

    @XmlTransient
    public List<Allocationid> getAllocationidList() {
        return allocationidList;
    }

    public void setAllocationidList(List<Allocationid> allocationidList) {
        this.allocationidList = allocationidList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Mobiledevice)) {
            return false;
        }
        Mobiledevice other = (Mobiledevice) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.pp.entites.Mobiledevice[ id=" + id + " ]";
    }
    
}
